package fudan.se.project.controller.conference.action;


import fudan.se.project.controller.request.PaperSubmitRequest;
import fudan.se.project.controller.request.RebuttalSubmitRequest;
import fudan.se.project.service.advanced.conference.action.AuthorActionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/user/conference/author")
public class AuthorActionController {

    private final AuthorActionService authorActionService;

    @Autowired
    public AuthorActionController(AuthorActionService authorActionService) {
        this.authorActionService = authorActionService;
    }

    @PostMapping("/submitPaper")
    public ResponseEntity<?> submitPaper(
            @Validated @RequestPart(value = "paperData") PaperSubmitRequest request,
            @RequestPart(value = "file") MultipartFile file
    ) {

        return authorActionService.submitPaper(request, file);
    }

    @GetMapping("/papers")
    public ResponseEntity<?> getPapers(@RequestParam long id) {

        return authorActionService.getPapers(id);
    }

    @GetMapping("/paper/reviewInfos")
    public ResponseEntity<?> getReviewInfos(@RequestParam long id) {

        return authorActionService.getReviewInfos(id);
    }


    @PostMapping("/paper/update")
    public ResponseEntity<?> updatePaper(
            @Validated @RequestPart(value = "paperData") PaperSubmitRequest request,
            @RequestPart(value = "file") MultipartFile file
    ) {

        return authorActionService.updatePaper(request, file);
    }

    @PostMapping("/submitRebuttal")
    public ResponseEntity<?> submitRebuttal(
            @Validated @RequestBody RebuttalSubmitRequest request
    ) {
        log.info("Author submits rebuttal for paper:" + request.getId());
        return authorActionService.submitRebuttal(request);
    }

}
